# 定义和调用
def func():
    print("Python")


func()

# 参数
def sum(num1, num2):
    print(num1 + num2)


sum(1, 2)

# return
def minus(num1, num2):
    return num1 - num2


result = minus(1, 2)
print("结果是 %d：" %result)

# 参数类型
# 缺省参数
def power(x, n = 2):  # n：默认参数，缺省参数
    return x ** n


print(power(4))
# 可变参数：*
def total(*args):  # 可变参数是tuple
    sum = 0
    for i in args:
        sum += i
    return sum


print(total(1, 2, 3))
print(total(*[1, 2, 3]))  # 传入列表要带*，类似解码

def f(**kwargs):  # 可变参数，接受字典
    for k, v in kwargs.items():
        print(k, v)


d = {"name": "jack", "age": 18}
f(**d)  # 传值的时候也要带**

print("-" * 10)
def mix(a, *b, c = 2):
    sum = 0
    for i in b:
        sum += i
    return a + sum + c


print(mix(1, *[2, 3]))
print(mix(1 ,*[2, 3], ))